package PTA.练习0502;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 25228
 * Date: 2024-11-14
 * Time: 9:08
 */

import java.util.Scanner;
interface Operable {
    public void turnOn();
    public void turnOff();
}
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Operable fan = new Fan();
        fan.turnOff();
        System.out.println(fan);
        ((Fan)fan).setColor("blue");
        int radius = input.nextInt();
        try {
            ((Fan)fan).setRadius(radius);
        }
        catch(IllegalArgumentException ex) {
            if(radius > 10)
                ((Fan)fan).setRadius(10);
            if(radius < 2)
                ((Fan)fan).setRadius(2);
        }
        int speed = input.nextInt();
        try {
            ((Fan)fan).setSpeed(speed);
        }
        catch(IllegalArgumentException ex) {
            if(speed > Fan.FAST)
                ((Fan)fan).setSpeed(Fan.FAST);
            if(radius < Fan.SLOW)
                ((Fan)fan).setSpeed(Fan.SLOW);
        }
        fan.turnOn();
        System.out.println(fan);
        input.close();

    }
}

class Fan implements Operable{
    static final int SLOW=1;
    static final int MEDIUM=2;
    static final int FAST=3;
    private int speed=SLOW;
    private boolean on=false;
    private double radius=5;
    private String color="blue";
    Fan(){

    }

    public int getSpeed() {
        return speed;
    }

    public boolean isOn() {
        return on;
    }

    public double getRadius() {return radius;}

    public String getColor() {
        return color;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public void setOn(boolean on) {this.on = on;}

    public void setRadius(double radius) {
        if(radius>10){
            radius=10;
        }
        if(radius<2){
            radius=2;
        }
        this.radius= radius;
    }

    public void setColor(String color) {
        this.color = color;
    }

    @Override
    public void turnOn() {
        this.on=true;
    }

    @Override
    public void turnOff() {
        this.on=false;
    }

    @Override
    public String toString() {
        if(on){
            String s;
            if(getSpeed()==1){
                s="SLOW";
            }else if (getSpeed()==2){
                s="MEDIUM";
            }else {
                s="FAST";
            }
            return '('+s+", "+getColor()+", "+getRadius()+')';
        }else {
            return '('+"off"+", "+getColor()+", "+getRadius()+')';
        }
    }
}

